#!/usr/bin/python3
#Copyright Bail 2024
#old-phone-monitor:client 旧手机监视器客户端 v0.1_0
#2024.7.28

URL = 'http://3pc2078st722.vicp.fun/old-phone-monitor/'

from deskcopy import log,cmd
import requests,time,os,deskcopy,threading,sys

def thread_autoupdate():
    '''自动更新线程'''
    day = time.strftime('%d')
    while True:
        newday = time.strftime('%d')
        if newday == day:
            log('I','日常更新')
            if cmd('git pull') == 0:
                report('更新成功')
            else:
                report('更新失败')
        time.sleep(6*60*60) # 6小时检测一次
def report(msg:str):
    '''向服务器报告消息
msg(str):报告的消息'''
    url = URL+'message_report'
    params = {'msg':msg}
    i = 0
    while i<3:
        try:
            requests.get(url=url,params=params)
        except:
            raise
        else:
            break
        i += 1
def main():
    threading.Thread(target=thread_autoupdate).start()
    return 0

if __name__ == '__main__':
    sys.exit(main())
